package roboticsfmw.sample.processor;

import roboticsfmw.annotation.HardwareRef;
import roboticsfmw.annotation.OnEvent;
import roboticsfmw.annotation.TimerRef;
import roboticsfmw.core.Processor;
import roboticsfmw.core.Timer;
import roboticsfmw.sample.event.JoystickEvent;
import roboticsfmw.sample.hardware.UserIOHardwareProxy;


public class ArmProcessor extends Processor {

	@HardwareRef(name = "/hw/userIO")
	private UserIOHardwareProxy userIOhw;
	
	@TimerRef(name = "/timer/InactivityTimer")
	public Timer inactivityTimer;

	public ArmProcessor(String name, long pollInterval, boolean loop) throws IllegalArgumentException {
		super(name, pollInterval, loop);
	}

	@Override
	public void init() {
	}

	@OnEvent(JoystickEvent.class)
	public void onJoystickEvent(JoystickEvent event) {
		
		inactivityTimer.reset();
		
		if (event.isXChanged()) {
			userIOhw.moveArmX((int) event.getX());
		}

		if (event.isYChanged()) {
			userIOhw.moveArmY((int) event.getY());
		}

		if (event.isB1()) {
			userIOhw.moveHand(1);
		} else if (event.isB2()) {
			userIOhw.moveHand(0);
		}
	}

	@Override
	public void shutdown() {
	}

	@Override
	public void loop(long i) {
	}

	public void setUserIOhw(UserIOHardwareProxy userIOhw) {
		this.userIOhw = userIOhw;
	}

	public UserIOHardwareProxy getUserIOhw() {
		return userIOhw;
	}

}
